package org.pisces.cas;

import org.apereo.cas.web.flow.AbstractCasWebflowConfigurer;
import org.apereo.cas.web.flow.CasWebflowConstants;
import org.apereo.cas.web.support.WebUtils;
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
import org.springframework.webflow.engine.Flow;
import org.springframework.webflow.engine.ViewState;
import org.springframework.webflow.engine.builder.BinderConfiguration;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;

public class SomethingWebflowConfigurer extends AbstractCasWebflowConfigurer {

	public SomethingWebflowConfigurer(FlowBuilderServices flowBuilderServices,
			FlowDefinitionRegistry flowDefinitionRegistry) {
		super(flowBuilderServices, flowDefinitionRegistry);
	}

	@Override
	protected void doInitialize() throws Exception {
		final Flow flow = getLoginFlow();
        bindCredential(flow);		
	}


    protected void bindCredential(Flow flow) {
        createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, MyCredential.class);
        final ViewState state = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM);
        final BinderConfiguration cfg = getViewStateBinderConfiguration(state);
        cfg.addBinding(new BinderConfiguration.Binding("code", null, false));
        cfg.addBinding(new BinderConfiguration.Binding("rememberMe", null, false));
    }
}